<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        body{
            margin-bottom:500px;
        }
    </style>
</head>
<body>
    <div id="app">
        <p>fDate:{{date | fDate()}}</p>
        <p>全局:{{date | aaa}}</p>
    </div>
    <div id="root">
        <p>fDate:{{date | fDate()}}</p>
        <p>全局:{{date | aaa}}</p>
    </div>
</body>
<script>
    Vue.filter("aaa",function(){
        console.log("aaa");
    })
    Vue.filter("fDate",function(date,arg){
        if(!(date instanceof Date) && typeof date == "number"){
            date=new Date(date);
        }else if(!date instanceof Date){
            return date;
        }
        let y=date.getFullYear();
        let m=(date.getMonth()+1)>=10?(date.getMonth()+1):"0"+(date.getMonth()+1);
        let d=(date.getDate()+1)>=10?(date.getDate()+1):"0"+(date.getDate()+1);
        let h=(date.getHours()+1)>=10?(date.getHours()+1):"0"+(date.getHours()+1);
        let M=(date.getMinutes()+1)>=10?(date.getMinutes()+1):"0"+(date.getMinutes()+1);
        let s=(date.getSeconds()+1)>=10?(date.getSeconds()+1):"0"+(date.getSeconds()+1);
        if(!arg){
            return y+"/"+m+"/"+d+" "+h+":"+M+":"+s;
        }
        arg=arg.replace("y",y);
        arg=arg.replace("m",m);
        arg=arg.replace("d",d);
        arg=arg.replace("h",h);
        arg=arg.replace("M",M);
        arg=arg.replace("s",s);
        return arg;
    })
    new Vue({
        el:"#app",
        data:{
            date:new Date()
        },
        filters:{
            aaa(){
                console.log("局部过滤器aaa");
            }
        }
    })
    new Vue({
        el:"#root",
        data:{
            date:new Date()
        }
    })
</script>
</html>